#include "Camera.h"
#include <glm/gtc/matrix_transform.hpp>

namespace DYEngine
{
	Camera::Camera(): Component() {}

	Camera::Camera(CameraType type): Component(), mType(type) {}

	Camera::~Camera() 
	{
		int a = 2;
	}

	glm::mat4x4 Camera::GetProjMatrix()
	{
		if (isDirty)
		{
			if (mType == CameraType::Ortho)
				mOrthoMat = glm::ortho(-mSize * mAspect, mSize * mAspect, -mSize, mSize, mZNear, mZFar);
			else
				mPerspMat = glm::perspective(glm::radians(mFov), mAspect, mZNear, mZFar);
		}

		if (mType == CameraType::Ortho)
			return mOrthoMat;
		else
			return mPerspMat;
	}

	glm::mat4x4 Camera::GetVPMatrix()
	{
		glm::mat4x4 vMat = GetTransform()->GetInverseMatrix();
		glm::mat4x4 pMat = GetProjMatrix();
		return pMat * vMat;
	}

	void Camera::Init()
	{

	}

	void Camera::Enable()
	{

	}

	void Camera::Update()
	{

	}

	void Camera::Disable()
	{

	}

	void Camera::Destroy()
	{
		
	}

	static Camera* sMainCamera = nullptr;

	int Camera::sWidth = 1;
	int Camera::sHeight = 1;

	Camera* Camera::GetMainCamera()
	{
		return sMainCamera;
	}

	void Camera::SetMainCamera(Camera* pCamera)
	{
		sMainCamera = pCamera;
	}
}
